package com.doerit.laptops.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.doerit.laptops.dao.StaffMapper;
import com.doerit.laptops.entity.Staff;
import com.doerit.laptops.service.ExistValidationEnum;
import com.doerit.laptops.service.StaffService;
import com.doerit.laptops.util.Pager;

@Service("staffService")
public class StaffServiceImpl extends AbstractListService implements StaffService {
	
	@Autowired
	private StaffMapper staffMapper;
	
	@Override
	public List<Staff> findAll() {
		return staffMapper.findAll();
	}

	@Override
	public Staff findById(Integer id) {
		return staffMapper.selectByPrimaryKey(id);
	}

	@Override
	public int update(Staff entity) {
		return this.staffMapper.updateByPrimaryKeySelective(entity);
	}

	@Override
	public int delete(Staff entity) {
		return this.delete(entity.getId());
	}

	@Override
	public int delete(Integer id) {
		return this.staffMapper.deleteByPrimaryKey(id);
	}

	@Override
	public Staff signIn(String email, String password) {

		List<Staff> list = staffMapper.findByEmailAndPassword(email, password);

		if (list == null) {
			// error
		} else if (list.size() == 0) {
			// user not found
		} else if (list.size() > 1) {
			// too many users
		} else {
			return list.get(0);
		}

		return null;
	}

	public ExistValidationEnum emailExistValidation(String email) {
		List<Staff> list = staffMapper.findByEmailAddress(email);

		if (list == null || list.size() == 0) {
			return ExistValidationEnum.NOT_EXIST;
		} else if (list.size() == 1) {
			return ExistValidationEnum.EXIST;
		} else {
			return ExistValidationEnum.MULTIPLE_EXIST;
		}
	}

	@Override
	public Staff findStaffByEmail(String email) {

		List<Staff> list = staffMapper.findByEmailAddress(email);

		if (list == null || list.size() == 0) {
			return null;
		} else if (list.size() == 1) {
			return list.get(0);
		} else {
			// error
			return null;
		}
	}

	@Override
	public List<Staff> findAllNotDisabled() {
		
		return null;
	}

	@Override
	public List<Staff> findAllDisabled() {
		
		return null;
	}

	@Override
	public int save(Staff entity) {
		
		return 0;
	}

	@Override
	public int save(Staff entity, Integer systemUserID) {
		
		return 0;
	}

	@Override
	public int update(Staff entity, Integer systemUserID) {
		
		return 0;
	}

	@Override
	public Pager viewPaginatedActiveList(Integer start, Integer size) {
		
		return null;
	}

	@Override
	public int getCount() {
		
		return 0;
	}

	@Override
	public Staff findLastLogin() {
		
		return null;
	}

	@Override
	public ExistValidationEnum emailExistValidation(String email, Integer id) {
		
		return null;
	}

	@Override
	public int saveWithPasswordRecords(Staff systemUser, Integer userId) {
		
		return 0;
	}




	
}
